#include "client.h"

//分析命令
int CommandAnalyse(char* command, char* pathname) {
    char commandType[64] = {0};
    int i;
    //分离命令关键字和路径名
    for(i = 0; i < (int)strlen(command); i++) {
        if(command[i] == ' ' || command[i] == 0) {
            break;
        } else {
            commandType[i] = command[i];
        }
    }
    while(command[i] == ' ') {
        i++;
    }
    strcpy(pathname, command + i);
    //判断命令类型
    if(strcmp(commandType, "cd") == 0) {
        return _CDDIR;
    } else if(strcmp(commandType, "ls") == 0) {
        return _LSDIR;
    } else if(strcmp(commandType, "mkdir") == 0) {
        return _MKDIR;
    } else if(strcmp(commandType, "rm") == 0) {
        return _RMFILE;
    } else if(strcmp(commandType, "pwd") == 0) {
        if(strlen(pathname) != 0) {
            return -1;
        } else {
            return _PWDDIR;
        }
    } else if(strcmp(commandType, "get") == 0) {
        return _GETFILE;
    } else if(strcmp(commandType, "put") == 0) {
        return _PUTFILE;
    } else {
        return -1;
    }
}
